

package com.mt.restaurant.controller.sale;

import com.mt.restaurant.dto.sale.ChangeMenuRecordDto;
import com.mt.restaurant.entity.sale.MenuSaleRecord;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import com.mt.common.core.annotation.ApiPageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mt.common.core.web.base.PageDTO;
import com.mt.common.core.web.base.PageResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



import com.mt.restaurant.dto.sale.SaleOrderEditDto;
import com.mt.restaurant.entity.sale.SaleOrder;
import com.mt.restaurant.service.sale.SaleOrderService;
										

@Api(tags = "销售订单")
@RestController
@RequestMapping("/api/restaurant/sale/SaleOrder")
@CrossOrigin(allowCredentials = "true")
public class SaleOrderController {
private static Logger logger = LoggerFactory.getLogger(SaleOrderController.class);



																																	@Autowired private SaleOrderService saleOrderService;
	
	/**
	* 根据分页参数查询销售订单集合
	*
	* @param pageDTO 分页条件
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:SaleOrder:view')")
	@ApiOperation("分页查询销售订单")
	@ApiPageParam
	@PostMapping("/findSaleOrders")
	public PageResultDTO findSaleOrders(@RequestBody PageDTO pageDTO){
		return this.saleOrderService.findSaleOrders(pageDTO);
	}

	/**
	* 根据ID查询指定的销售订单
	*
	* @param saleOrderId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:SaleOrder:view')")
	@ApiOperation("根据id查询销售订单")
	@ApiPageParam
	@PostMapping("/findSaleOrder")
	public SaleOrder findSaleOrder(@RequestParam Long saleOrderId){
		return this.saleOrderService.findSaleOrder(saleOrderId);
	}

	/**
	* 根据ID查询指定的销售订单(包含外键名称)
	*
	* @param saleOrderId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:SaleOrder:view')")
	@ApiOperation("根据ID查询指定的销售订单(包含外键名称)")
	@PostMapping("/findSaleOrderForView")
	public SaleOrder findSaleOrderForView(@RequestParam Long saleOrderId){
		return this.saleOrderService.findSaleOrderWithForeignName(saleOrderId);
	}

	/**
	* 根据ID查询指定的销售订单(包含销售订单和外键名称)
	*
	* @param saleOrderId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:SaleOrder:view')")
	@ApiOperation("根据ID查询指定的销售订单(包含销售订单和外键名称)")
	@PostMapping("/findSaleOrderForEdit")
	public SaleOrderEditDto findSaleOrderForEdit(@RequestParam Long saleOrderId){
				SaleOrderEditDto saleOrderEditDto = new SaleOrderEditDto();
		saleOrderEditDto.setSaleOrder(this.saleOrderService.findSaleOrderWithForeignName(saleOrderId));

		this.prepareSaleOrderEditDto(saleOrderEditDto);

		return saleOrderEditDto;
	}

	/**
	* 根据ID查询指定的销售订单(只提取ID 和 Name)
	*
	* @param saleOrderId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:SaleOrder:view')")
	@ApiOperation("根据ID查询指定的销售订单(只提取ID 和 Name)")
	@PostMapping("/findSaleOrdersWithIdNameById")
	public SaleOrder findSaleOrdersWithIdNameById(@RequestParam Long saleOrderId){
	return this.saleOrderService.findSaleOrdersWithIdNameById(saleOrderId);
	}

	/**
	* 根据名称查询销售订单集合(只提取ID 和 Name)
	*
	* @param saleOrderName 名称
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:SaleOrder:view')")
	@ApiOperation("根据名称查询销售订单集合(只提取ID 和 Name)")
	@PostMapping("/findSaleOrdersWithIdNameByName")
	public List<SaleOrder> findSaleOrdersWithIdNameByName(@RequestParam String saleOrderName){
	return this.saleOrderService.findSaleOrdersWithIdNameByName(saleOrderName);
	}


	/**
	* 创建新的销售订单
	*
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:SaleOrder:add')")
	@ApiOperation("创建新的销售订单")
	@PostMapping("/createSaleOrder")
	public SaleOrderEditDto createSaleOrder(){
				SaleOrderEditDto saleOrderEditDto = new SaleOrderEditDto();
		saleOrderEditDto.setSaleOrder(new SaleOrder());

		this.prepareSaleOrderEditDto(saleOrderEditDto);
		return saleOrderEditDto;
	}

	private void prepareSaleOrderEditDto(SaleOrderEditDto saleOrderEditDto){
																																}

	/**
	* 新增保存销售订单
	*
	* @param saleOrder 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:SaleOrder:add')")
	@ApiOperation("新增保存销售订单")
	@PostMapping("/saveSaleOrder")
	public SaleOrder saveSaleOrder(@RequestBody SaleOrder saleOrder){
		return this.saleOrderService.saveSaleOrder(saleOrder);
	}

	/**
	* 修改保存销售订单
	*
	* @param saleOrder 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:SaleOrder:update')")
	@ApiOperation("修改保存销售订单")
	@PostMapping("/updateSaleOrder")
	public SaleOrder updateSaleOrder(@RequestBody SaleOrder saleOrder){
		return this.saleOrderService.updateSaleOrder(saleOrder);
	}

	/**
	* 根据ID删除销售订单
	*
	* @param saleOrderId ID
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:SaleOrder:remove')")
	@ApiOperation("根据ID删除销售订单")
	@PostMapping("/deleteSaleOrder")
	public void deleteSaleOrder(@RequestParam Long saleOrderId){
		this.saleOrderService.deleteSaleOrder(saleOrderId);
	}

	@ApiOperation("修改订单的菜单")
	@PostMapping("/changeOrderMenu")
	public void changeOrderMenu(@RequestBody ChangeMenuRecordDto changeMenuRecordDto){
		this.saleOrderService.changeOrderMenu(changeMenuRecordDto);
	}

}

